// pages/evaluate/evaluate.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    orderId: 0,
    info: {},
    nums: 5,
  },

  chooseicon: function (e) {
    var strnumber = e.target.dataset.id;
    var _obj = {};
    _obj.curHdIndex = strnumber;
    this.setData({
      tabArr: _obj,
      nums: strnumber,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var orderId = options.orderId;
    that.setData({
      orderId: orderId,
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var orderId = that.data.orderId;
    wx.request({
      url: app.api.hostUrl + '/Api/Order/details',
      method: 'post',
      data: {
        uid: app.api.userId,
        order_id: orderId,
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        var status = res.data.status;
        var info = res.data.info;
        if (status == 1) {
          that.setData({
            info: info,
          });
        } else {
          wx.showToast({
            title: res.data.err,
            duration: 2000
          });
        }
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      },
    })
  },

  //提交评价
  bindFormSubmit: function (e) {
    var that = this;
    var content = e.detail.value.textarea;
    wx.request({
      url: app.api.hostUrl + '/Api/Order/addMessage',
      method: 'post',
      data: {
        uid: app.api.userId,
        order_id: that.data.orderId,
        docid: that.data.info.docid,
        nums: that.data.nums,
        content: content,
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        var status = res.data.status;
        if (status==1) {
          wx.showToast({
            title: '评价成功！',
            duration: 2000
          });
          setTimeout(function(e){
            wx.navigateTo({
              url: '../orders/orders?currentTab=3&otype=finish',
            });
          },2500);
        } else {
          wx.showToast({
            title: res.data.err,
            duration: 2000
          });
        }
      },
      fail: function () {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})